#include<bits/stdc++.h>
using namespace std;
#define int long long
int d[100005],v[100005],a[100005];
int p[100005];
int dp[100005];
vector<int>g[100005];
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    for(int id=1;id<=t;id++){
        
        int n,m,L,V;
        cin>>n>>m>>L>>V;    
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++)cin>>p[i];
        sort(p+1,p+1+m);
        // for(int i=1;i<=m;i++)cout<<p[i]<<' 'p
        vector<pair<int,int>>w;
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V){
                    int l=d[i],r=L;
                    int ll=lower_bound(p+1,p+1+m,l)-p,rr=upper_bound(p+1,p+1+m,r)-p-1;
                    if(ll<=rr)w.push_back({ll,rr});
                    // cout<<i<<' '<<ll<<' '<<rr<<'\n';
                }
            }
            if(a[i]>0){
                int l=d[i]-1,r=L+1;
                while(l+1<r){
                    int mid=(l+r)>>1; 
                    int s=mid-d[i];
                    if(v[i]*v[i]+2*a[i]*s>V*V)r=mid;
                    else l=mid;
                }
                int ll=lower_bound(p+1,p+1+m,r)-p,rr=upper_bound(p+1,p+1+m,L)-p-1;
                if(ll<=rr)w.push_back({ll,rr});
                // cout<<i<<' '<<ll<<' '<<rr<<'\n';
            }
            if(a[i]<0){
                int l=d[i]-1,r=L+1;
                while(l+1<r){
                    int mid=(l+r)>>1;
                    int s=mid-d[i];
                    if(v[i]*v[i]+2*a[i]*s>V*V)l=mid;
                    else r=mid;
                }
                int ll=lower_bound(p+1,p+1+m,d[i])-p,rr=upper_bound(p+1,p+1+m,l)-p-1;
                if(ll<=rr)w.push_back({ll,rr});
                // cout<<i<<' '<<ll<<' '<<rr<<'\n';
            }
        }
        cout<<w.size()<<' ';
        if(!w.size()){
            cout<<m<<'\n';
        }else{
            for(int i=1;i<=m+1;i++)dp[i]=1e9;
            dp[0]=0;
            for(int i=1;i<=m+1;i++)g[i].clear();
            for(auto p:w)g[p.second].push_back(p.first);
            deque<int>z;
            z.push_back(0);
            int mili=0;
            for(int i=1;i<=m+1;i++){
                while(z.size()&&z.front()<mili)z.pop_front();
                dp[i]=dp[z.front()]+1;
                while(z.size()&&dp[z.back()]>=dp[i])z.pop_back();
                z.push_back(i);
                for(auto x:g[i]){
                    mili=max(mili,x);
                }
            }
            cout<<m-(dp[m+1]-1)<<'\n';
        }
        
    }
    return 0;
}